/**
 * 
 * Copyright (C) 2015 by Elcom Software Company
 *
 * @id: DBCfg.java, Feb 5, 2015
 *
 */
package com.nip.commons.dbcp;

import java.io.InputStream;

import com.nip.commons.dbcp.interf.IDBConfig;
import com.nip.commons.xmlconfig.XmlConfigBase;

/**
 * @author ThangNM<thangnm@elcom.com.vn>
 * 
 * @version v
 */
public class DBCfg extends XmlConfigBase implements IDBConfig {

    boolean valid = true;

    public DBCfg(String configPath) throws Exception {
        super("dbcp");
        load(configPath);
    }
    
    public DBCfg(InputStream is) throws Exception {
        super("dbcp");
        load(is);
    }
    /*
     * (non-Javadoc)
     * 
     * @see com.nip.commons.dbcp.interf.IDBConfig#isValid()
     */
    @Override
    public boolean isValid() {
        // TODO Auto-generated method stub
        return valid;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.nip.commons.dbcp.interf.IDBConfig#getDriver()
     */
    @Override
    public String getDriver() {
        // TODO Auto-generated method stub
        return getValue("db.driver","");
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.nip.commons.dbcp.interf.IDBConfig#getUrl()
     */
    @Override
    public String getUrl() {
        // TODO Auto-generated method stub
        return getValue("db.url","");
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.nip.commons.dbcp.interf.IDBConfig#getUsername()
     */
    @Override
    public String getUsername() {
        // TODO Auto-generated method stub
        return getValue("db.username","");
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.nip.commons.dbcp.interf.IDBConfig#getPassWord()
     */
    @Override
    public String getPassWord() {
        // TODO Auto-generated method stub
        return getValue("db.password","");
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.nip.commons.dbcp.interf.IDBConfig#getCacheState()
     */
    @Override
    public boolean getCacheState() {
        // TODO Auto-generated method stub
        return getBoeanValue("pool.cachestate", false);
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.nip.commons.dbcp.interf.IDBConfig#getAutoCommit()
     */
    @Override
    public boolean getAutoCommit() {
        // TODO Auto-generated method stub
        return getBoeanValue("pool.defaultautocommit", false);
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.nip.commons.dbcp.interf.IDBConfig#getInitialSize()
     */
    @Override
    public int getInitialSize() {
        // TODO Auto-generated method stub
        return getIntValue("pool.initialSize");
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.nip.commons.dbcp.interf.IDBConfig#getMaxTotal()
     */
    @Override
    public int getMaxTotal() {
        // TODO Auto-generated method stub
        return getIntValue("pool.maxTotal");
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.nip.commons.dbcp.interf.IDBConfig#getMaxIdle()
     */
    @Override
    public int getMaxIdle() {
        // TODO Auto-generated method stub
        return getIntValue("pool.maxIdle");
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.nip.commons.dbcp.interf.IDBConfig#getMinIdle()
     */
    @Override
    public int getMinIdle() {
        // TODO Auto-generated method stub
        return getIntValue("pool.minIdle");
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.nip.commons.dbcp.interf.IDBConfig#getMaxWaitMillis()
     */
    @Override
    public long getMaxWaitMillis() {
        // TODO Auto-generated method stub
        return getLongValue("pool.maxWaitMillis");
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.nip.commons.dbcp.interf.IDBConfig#getValidationQuery()
     */
    @Override
    public String getValidationQuery() {
        // TODO Auto-generated method stub
        return getValue("pool.validationQuery","");
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.nip.commons.dbcp.interf.IDBConfig#getMaxConnLifetimeMillis()
     */
    @Override
    public long getMaxConnLifetimeMillis() {
        // TODO Auto-generated method stub
        return getLongValue("pool.maxConnLifetimeMillis");
    }

    /* (non-Javadoc)
     * @see com.nip.commons.dbcp.interf.IDBConfig#getLoginTimeout()
     */
    @Override
    public int getLoginTimeout() {
        // TODO Auto-generated method stub
        return getIntValue("pool.loginTimeout");
    }

}
